<template>
  <div class="home_menu">
    <el-menu
      :default-active="menuActive"
      background-color="#180300"
      text-color="#fff"
      active-text-color="#ffd04b"
      class="home_menu_box"
      :unique-opened="uniqueOpened"
      @click.native="yuio"
      router
    >
      <el-menu-item v-if="userType == 0" index="/match/list"
        >赛事管理</el-menu-item
      >

      <el-menu-item v-if="userType == 0" index="/department/list"
        >部门管理</el-menu-item
      >
      <el-menu-item v-if="userType == 0" index="/workflow/list"
        >流程管理</el-menu-item
      >

      <el-menu-item v-if="userType == 0" index="/user/list"
        >用户管理</el-menu-item
      >

      <el-menu-item v-if="userType == 0" index="/blacklist/list"
        >黑名单</el-menu-item
      >

      <el-submenu index="2">
        <template slot="title">报名管理</template>
        <el-menu-item index="/audit/list" v-if="userType == 0 || userType == 1"
          >报名</el-menu-item
        >
        <el-menu-item
          index="/Auditlistpuss/list"
          v-if="userType == 0 || userType == 1"
          >待审核</el-menu-item
        >
        <el-menu-item
          index="/Auditedlist/list"
          v-if="userType == 0 || userType == 1"
          >已审核</el-menu-item
        >
        <el-menu-item
          index="/enroll/list"
          v-if="userType == 2 || userType == 0 || userType == 1"
          >报名名单</el-menu-item
        >
        <el-menu-item v-if="userType == 0" index="/certificationList/list"
          >制证名单</el-menu-item
        >
      </el-submenu>

      <el-menu-item @click="logoutBtn()">
        <span slot="title">退出系统</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "HomeMenu",
  props: {},
  data() {
    return {
      userName: this.$store.state.loginUserName,
      menuActive: "", // 导航默认选中
      uniqueOpened: true,
      // userType: this.$store.state.loginUserType == "ADMINLOGINUSERCH", // 用户类型;1. 普通; 0. 超级;
      userType: localStorage.getItem("type"),
    };
  },
  created: function () {
    this.setMenuActive();
  },
  methods: {
    // 设置选择
    setMenuActive: function () {
      let path = this.$route.path;
      if (path.indexOf("/department/") == 0) {
        this.menuActive = "/department/list";
      } else if (path.indexOf("/workflow/") == 0) {
        this.menuActive = "/workflow/list";
      } else if (path.indexOf("/match/") == 0) {
        this.menuActive = "/match/list";
      } else if (path.indexOf("/blacklist/") == 0) {
        this.menuActive = "/blacklist/list";
      } else {
        this.menuActive = path;
      }
    },
    // 退出登录
    logoutBtn: function () {
      let that = this;
      this.$confirm("确认退出?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          that.$store.commit("set_loginToken", "");
          that.$store.commit("set_loginUserId", "");
          that.$store.commit("set_loginUserName", "");
          that.$router.push({
            name: "Login",
          });
        })
        .catch(() => {});
    },
    yuio() {
      if (
        sessionStorage.getItem("companyKey") != "" ||
        sessionStorage.getItem("even_id") != ""
      ) {
        sessionStorage.removeItem("companyKey");
        sessionStorage.removeItem("even_id");
      }
    },
  },
  watch: {
    // 监听路有变化
    $route: "setMenuActive",
  },
};
</script>
